package com.yanqu.road.server.cmd.wineshop;

import com.yanqu.road.pb.wineshop.WineShopProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wineshop.WineShopModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/7/20 15:45
 */
@Cmd(code = GameProtocol.S_WINESHOP_UNLOCK_BUILDING, desc = "酒肆解锁建筑")
public class WineShopUnlockBuildingCmd extends AbstractCommand {
    private int buildingId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WineShopProto.WineShopUnlockBuildingReqMsg msg = WineShopProto.WineShopUnlockBuildingReqMsg.parseFrom(packet.getBytes());
        buildingId = msg.getBuildingId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WineShopModule.class).unlockBuilding(buildingId);
    }

    @Override
    public void sendData(GamePlayer player) {
        WineShopProto.WineShopUnlockBuildingRespMsg.Builder respMsg = WineShopProto.WineShopUnlockBuildingRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_WINESHOP_UNLOCK_BUILDING, respMsg);
    }
}
